<template>
	<view style="padding: 30prx;">
		<view>异步接口</view>
		<button @click="callStorageFun(1)" type="primary">setStorage</button>
		<button @click="callStorageFun(2)" type="primary" plain="true">getStorage</button>
		<button @click="callStorageFun(3)" type="warn">getStorageInfo</button>
		<button @click="callStorageFun(4)" type="warn">RemoveStorage</button>
		<button @click="callStorageFun(5)" type="warn">clearStorage</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			callStorageFun(parm){
				console.log("callStorageFun==> parm"+parm);
				switch(parm){
					case 1:
					uni.setStorage({
						key:'Username',
						data:'cy',
						success(){
							console.log("Username 存储成功");
						}
					})
					break;
					case 2:
					uni.getStorage({
						key:'Username',
						//回调接口
						success:function(result){
							console.log("读取Username成功 result.data="+result.data);
						},
						fail(){
							console.log("读取Username失败");
						}
					});
					  break;
					  case 3:
					  uni.getStorageInfo({
					  	success:function(result){
					  		console.log("获取所有缓存字段:"+result.keys);
					  	}
					  })
					  break;
					  case 4:
					  uni.removeStorage({
					  	key:'Username',
						success() {
							console.log("Username删除成功");
						}
					  })
					  break;
				}
			}
		}
	}
</script>

<style>

</style>
